package com.clkj.sunhelp.mvp.seekhelpnew.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.clkj.sunhelp.R;
import com.clkj.sunhelp.mvp.seekhelpnew.WebserviceConfig;
import com.clkj.sunhelp.mvp.seekhelpnew.domain.QzxxListItem;
import com.clkj.sunhelp.util.viewutil.BitmapTransformation2;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2017/3/30.
 */

public class ListAdapterForQiuZhuItem extends BaseAdapter {


    List<QzxxListItem> mQzInfoList;
    Context mContext;
    LayoutInflater mLayoutInflater;

    public ListAdapterForQiuZhuItem(List<QzxxListItem> qzInfoList, Context context) {
        mQzInfoList = qzInfoList;
        mContext = context;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return mQzInfoList.size();
    }

    @Override
    public Object getItem(int position) {
        return mQzInfoList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder = null;
        if (convertView == null)
        {
            convertView = mLayoutInflater.inflate(R.layout.list_item_qiuzhu_item,null);
            viewHolder = new ViewHolder();
            viewHolder.ivQiuzhuPic = (ImageView) convertView.findViewById(R.id.iv_qiuzhu_pic);
            viewHolder.tvQiuzhuTitle = (TextView) convertView.findViewById(R.id.tv_qiuzhu_title);


            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }

        Picasso.with(mContext)
                .load(WebserviceConfig.HACIAIUPURL+mQzInfoList.get(position).getImgurl())
                .placeholder(R.drawable.default_pic_mid)
                .error(R.drawable.default_pic_mid)
                .transform(new BitmapTransformation2(mContext,R.drawable.default_pic_mid))
                .into(viewHolder.ivQiuzhuPic);

        viewHolder.tvQiuzhuTitle.setText(mQzInfoList.get(position).getTitle());

        return convertView;


    }

    static class ViewHolder{
        private ImageView ivQiuzhuPic;
        private TextView tvQiuzhuTitle;
    }




}
